<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Find Keyword Analysis Tool</title>
<script language="JavaScript" type="text/javascript">
/////////////////////////////////////////////////////////////////////////////
//
// Within this JavaScript solution, there is no sorting!
//
/////////////////////////////////////////////////////////////////////////////

// init
var aStopWords = new Array (
	"about",
	"all",
	"alone",
	"also",
	"am",
	"and",
	"as",
	"at",
	"because",
	"before",
	"beside",
	"besides",
	"between",
	"but",
	"by",
	"etc",
	"for",
	"i",
	"of",
	"on",
	"other",
	"others",
	"so",
	"than",
	"that",
	"though",
	"to",
	"too",
	"trough",
	"until"
);

function calc() {

	// init
	var aWords = new Array ();
	var aKeywords = new Array ();

	// the text
	var sText = document.f.text.value;

	// total character count
	var iCharCount = sText.length;

	// remove line breaks
	sText = sText.replace(/\s/g, ' ');

	// convert to lowercase
	sText = sText.toLowerCase();

	// remove peculiars
	sText = sText.replace(/[^a-zA-Z0-9äöüß]/g, ' ');

	// total word count
	aWords = sText.split(" ");
	iWordCount = aWords.length;
	var iCharCountWithout = 0;
	
	// count words
	for (var x = 0; x < aWords.length; x++) {
		iCharCountWithout += aWords[x].length;
	}

	aWords = new Array();

	// remove stop words
	for (var m = 0; m < aStopWords.length; m++) {
		sText = sText.replace(' ' + aStopWords[m] + ' ', ' ');
	}

	// explode to array of words
	aWords = sText.split(" ");
	
	// every word
	for (var x = 0; x < aWords.length; x++) {
		// trim the word
		var s = aWords[x].replace (/^\s+/, '').replace (/\s+$/, '');
		
		// if already in array
		if (aKeywords[s] != undefined) {
			// then increase count of this word
			aKeywords[s]++;
		}

		// if not counted yet
		else {
			if (s != '') {
				aKeywords[s] = 1;
			}
		}
	}
	
	// result
	sAlert = "Found keywords:";

	n = 1;
	for (var sKey in aKeywords) {
		iNumber = aKeywords[sKey];
		fQuotient = Math.round(100 * (iNumber / iWordCount), 2);
		sAlert = sAlert + "\n" + iNumber + " times (" + fQuotient + " %): " + sKey;
		n++;
		
		// break the loop if more then 10 results
		if (n > 10)
			break;
	}

	alert(sAlert);

}
</script>
</head>
<body>
<form action="#" name="f" method="get" onsubmit="calc(); return false;"><textarea name="text" cols="80" rows="20"></textarea><input type="submit" name="calculate" value="calculate"></form>
</body>
</html>